package com.test.jsonb;

import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;
import javax.json.bind.JsonbConfig;
import javax.json.bind.config.PropertyOrderStrategy;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;

public class MDemo {
	public static void main(String[] args) throws MalformedURLException {
		Magazine magazine = new Magazine();
		JsonbConfig jsonbConfig = new JsonbConfig()
		.withPropertyOrderStrategy(PropertyOrderStrategy.ANY)
		.withNullValues(true);
		Jsonb jsonb = JsonbBuilder.create(jsonbConfig);
		magazine.setId("ABCD-1234");
		magazine.setTitle("Fun with Java");
		magazine.setAuthor(new Author("Alex", "Theedom"));
		magazine.setPrice(45.00f);
		magazine.setPages(300);
		magazine.setInPrint(true);
//		magazine.setBinding(new Binding(null, magazine));
		magazine.setLanguages(
		    Arrays.asList("French", "English", "Spanish", null));
		magazine.setWebsite(new URL("https://www.readlearncode.com"));
		magazine.setInternalAuditCode("IN-675X-NF09");
		magazine.setPublished(LocalDate.parse("01/01/2018", 
		    DateTimeFormatter.ofPattern("MM/dd/yyyy")));
		magazine.setAlternativeTitle("IN-675X-NF09");
		String json = jsonb.toJson(magazine);
		//String json =JsonBuilder.create().toJson(magazine);
		System.out.println(json);

	}
}
